$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var userfile = $( "#file_upload" ),
			allFields = $( [] ).add( userfile ),
			tips = $( ".validateTips" );
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 180,
			width: 350,
			modal: true,
			buttons: {
				"Upload Photo": function() {
					if ( userfile.val() != "" ) {
						var loading = $("body").busyBox({
							spinner: '<img src="/images/admin/ajax-loader.gif" />'
						}); 
						
						$.ajax({
							type: "POST",
							//data: "url=" + url + "," + params,
							data: ({file_upload: userfile.val()}),
							url: "/admin/index/adminprofileimage/",
							success: function(html, textStatus, XMLHttpRequest){
							    $( "#dialog-form" ).dialog( "close" );
							    alert(html);
							},
							complete: function complete(XMLHttpRequest, textStatus){
								loading.busyBox('close');
								$( this ).dialog( "close" );
							}
						});						
					} else {
						alert("Please select a file first");
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );					
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

		$( "#upload_photo" )
			//.button()
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
	});